package com.jisuan.controller;

import com.jisuan.pojo.Equip;
import io.swagger.annotations.Api;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@Api
public class JsController {

    @PostMapping("/js")
    public HashMap<String,Integer> js(Equip equip){
        int count = 0;//个数
        int mainFz = 0;
        int qdFz = 0;
        int pfFz=0;

        if(equip.getMainType() != 0){
            count++;
            mainFz = fz(equip.getMaxType(),equip.getMinType(),equip.getMainType());
        }
        if(equip.getQd()!= 0 ){
            count ++;
            qdFz = fz(equip.getMaxQd(), equip.getMinQd(), equip.getQd());
        }
        if(equip.getPf()!= 0 ){
            count ++;
            pfFz = fz(equip.getMaxPf(), equip.getMinPf(), equip.getPf());
        }

        int sum = (mainFz + qdFz + pfFz) / 3;
        HashMap<String,Integer> map = new HashMap();
        map.put("总分:",sum);
        map.put("主属性分值:",mainFz);
        map.put("强度分值:",qdFz);
        map.put("破防分值",pfFz);
        return map;
    }

    private int fz(Integer max , Integer min , Integer me){
        Integer sx =  max - min;
        Integer xs = me - min;
        if(sx <0 || xs < 0){
            return 0;
        }
        Double fz = (double)xs / sx * 100;

        return fz.intValue();
    }
}
